package com.easyhuan.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.easyhuan.dao.GoodsUtil;
import com.easyhuan.pojo.Goods;
import com.easyhuan.pojo.PageInfo;
import com.easyhuan.pojo.User;
import com.opensymphony.xwork2.ActionSupport;

/***
 * 负责人：宋莹春 完成时间：2014/5/
 * ***/
public class GoodsSearch extends ActionSupport {
	private List<Goods> goodses;

	public List<Goods> getGoodses() {
		return goodses;
	}

	public void setGoodses(List<Goods> goodses) {
		this.goodses = goodses;
	}

	PageInfo page;

	public PageInfo getPage() {
		return page;
	}

	public void setPage(PageInfo page) {
		this.page = page;
	}

	HttpServletRequest request = ServletActionContext.getRequest();
	HttpSession session = ServletActionContext.getRequest().getSession();

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		GoodsUtil gd = new GoodsUtil();
		page = new PageInfo();
		User user = (User) session.getAttribute("currUser");

		String currPage = request.getParameter("currentPage");// 从前台页面中获取页码信息
		if (null != currPage) {
			int currentPage = Integer.parseInt(currPage);
			page.setCurrentPage(currentPage);
		}
		page.setShowNumber(5);// 设置每页显示的信息条数

		String hql = "Goods";
		page.setTotalNumber(gd.getResultCount(hql,"WHERE p.user.userId="+user.getUserId()));// 设置总条数

		this.goodses = gd.selectGoodsWithPage(user, page);
		return SUCCESS;
	}
}
